#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
    string minWindow(string s, string t) {
        int hash[123] = { 0 };
        int cmp[123] = { 0 };
        int begin = -1;
        int minlen = INT_MAX;
        for (auto e : t)
        {
            ++cmp[e];
        }
        for (int left = 0, right = 0, count = 0; right < s.size(); ++right)
        {
            if (hash[s[right]]++ < cmp[s[right]]) ++count;
            while (count == t.size())
            {
                if (right - left + 1 < minlen)
                {
                    begin = left; minlen = right - left + 1;
                }
                if (hash[s[left]]-- <= cmp[s[left++]]) --count;
            }
        }
        if (minlen == INT_MAX)
            return "";
        else
            return string(s, begin, minlen);
    }
};